import {standardUnitMap} from '@/libs/standardUtils'
import {PropType} from 'vue'

export const StandardSelect = defineComponent({
  props: {
    standardUnit: String as PropType<StandardUnit>
  },
  emits: {
    'update:standardUnit': (s: StandardUnit): boolean => true
  },
  setup(props, {emit}) {
    const state = reactive<{
      selected: StandardUnit | undefined
    }>({
      selected: undefined
    })

    watch(
      () => props.standardUnit,
      n => {
        state.selected = standardUnitMap(n)
      },
      {immediate: true}
    )

    watch(
      () => state.selected,
      n => {
        emit('update:standardUnit', n)
      }
    )

    return () => (
      <a-select
        class='w-142 text-left'
        v-model={[state.selected, 'value']}
        options={[
          {label: '两者之间', value: '-'},
          {label: '大于等于', value: '>='},
          {label: '小于等于', value: '<='}
        ]}
      ></a-select>
    )
  }
})
